//--------------------------------------------------------------------------------
// This file is a portion of the D2D1Renderer.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Mirco Timmermann
//
//--------------------------------------------------------------------------------
#include "Document.h"

Document::Document(int x, int y, int width, int height) : D2::ScrollBarContainer(x, y, width, height, ScrollBarContainer::ScrollBarType::VERTICAL) {
	int border = 0;

	_textBox = new TextBox(0+border, 0+border, width-border*2, height-border);
	_textBox->SetMode(TextBox::TextMode::SCROLL);
	_textBox->showBackground = false;
	_textBox->SetBgColor(1.0f, 1.0f, 1.0f);
	_textBox->SetFgColor(0.0f, 0.0f, 0.0f);
	
	_textBox->addEventListener("TOTAL_WIDTH_CHANGED", std::bind(&Document::ON_TOTAL_WIDTH_CHANGED_textBox, this, std::placeholders::_1));
	_textBox->addEventListener("TOTAL_HEIGHT_CHANGED", std::bind(&Document::ON_TOTAL_HEIGHT_CHANGED_textBox, this, std::placeholders::_1));

	this->addChild(_textBox);	
}

Document::~Document(void) {
	
}

void Document::AppendText(std::string text) {
	_textBox->AppendText(text);
}

void Document::SetWriteable(bool enable) {
	_textBox->_writeable = enable;
}

void Document::ON_TOTAL_WIDTH_CHANGED_textBox(const Event &event) {
	DisplayObject* displayObject = (DisplayObject*)event.data;

	//_textBox
}

void Document::ON_TOTAL_HEIGHT_CHANGED_textBox(const Event &event) {
	DisplayObject* displayObject = (DisplayObject*)event.data;

	this->_scrollBar->SetBarByHeight(_textBox->GetTotalHeight(), _textBox->_height);
}